// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef AOSP_COMPABILITY_JNI_H_
#define AOSP_COMPABILITY_JNI_H_

#include <vector>
#include <string>

typedef std::string jstring;
typedef std::vector<int> *jintArray;
typedef std::vector<float> *jfloatArray;
typedef int jint;
typedef long int jlong;
typedef float jfloat;
typedef size_t jsize;

class JNIEnv {
 public:
   void GetIntArrayRegion(jintArray array, jsize offset, jsize len, jint* buffer) {
      if (offset + len > array->size())
         return;
      std::copy(array->begin() + offset, array->begin() + offset + len, buffer);
   }
   void GetFloatArrayRegion(jfloatArray array, jsize offset, jsize len, jfloat* buffer) {
      if (offset + len > array->size())
         return;
      std::copy(array->begin() + offset, array->begin() + offset + len, buffer);
   }
   jsize GetArrayLength(jintArray array) {
      return array->size();
   }
   jsize GetArrayLength(jfloatArray array) {
      return array->size();
   }
   void GetStringUTFRegion(jstring str, jsize offset, jsize len, char* buffer) {
      if (offset + len > str.size())
         return;
      std::copy(str.begin() + offset, str.begin() + offset + len, buffer);
   }
   jsize GetStringUTFLength(jstring string) {
      return string.size();
   }
   jsize GetStringLength(jstring string) {
      return string.size();
   }
};

#endif
